package com.dragon.modules.yuegou.service.impl.message;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.message.TriggerEntity;
import com.dragon.modules.yuegou.enums.message.TriggerStatus;
import com.dragon.modules.yuegou.mapper.message.TriggerMapper;
import com.dragon.modules.yuegou.model.message.Trigger;
import com.dragon.modules.yuegou.query.message.TriggerQuery;
import com.dragon.modules.yuegou.service.message.TriggerService;
import com.dragon.modules.yuegou.web.Check;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 消息触发器（事件触发推送模板消息） 服务实现
 *
 * @author pbuilder generated
 * @date 2019-03-18 13:46:09
 * @version 2.0
 */
@Service("msgTriggerService")
public class TriggerServiceImpl
		extends ServiceImpl<TriggerMapper, TriggerEntity>
		implements TriggerService {

	@Override
	public void createTrigger(Trigger trigger){
		Check.notEmpty(trigger.getTitle(),"触发名称不能为空");
		Check.notNull(trigger.getTemplateId(),"模板名称不能为空");
		Check.notEmpty(trigger.getEventType(),"事件名称不能为空");
		Check.notEmpty(trigger.getArgNames(),"参数不能为空");
		if(StringUtils.isEmpty(trigger.getId())){
			//创建触发
			trigger.setDel(false);
			trigger.setStatus(TriggerStatus.ENABLED);
			trigger.setSupportSystem(true);
			trigger.setSupportEmail(true);
			trigger.setSupportJpush(true);
			trigger.setSupportSms(true);
			trigger.setSupportWechat(true);
			save(trigger);
		}else{
			updateById(trigger);
		}
	}

	@Override
	public void editStatus(String id, TriggerQuery query){
		Check.notNull(id,"id不能为空");
		Check.notNull(query.getStatus(),"状态不能为空");
		//修改触发状态
		Trigger trigger = new Trigger();
		trigger.setId(id);
		trigger.setStatus(query.getStatus());
		updateById(trigger);
	}

}